package cn.wolfcode.luowowo.mgrsite.job;

import cn.wolfcode.luowowo.acticle.service.IStrategyDetailService;
import cn.wolfcode.luowowo.acticle.vo.AswerStatisVo;
import cn.wolfcode.luowowo.acticle.vo.StrategyStatisVO;
import cn.wolfcode.luowowo.cache.service.IAswerRedisService;
import cn.wolfcode.luowowo.cache.service.IStrategyStatisRedisService;
import cn.wolfcode.luowowo.comment.service.IAnswerCommentService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 将redis中的数据定时持久化到mysql中
 */
@Component
public class RedisDataPersistenceJob {
    //Seconds Minutes Hours DayofMonth Month DayofWeek Year
    //Seconds Minutes Hours DayofMonth Month DayofWeek       springboot支持的

    @Reference
    private IStrategyStatisRedisService strategyStatisRedisService;
    @Reference
    private IStrategyDetailService strategyDetailService;
    @Reference
    private IAnswerCommentService answerCommentService;
    @Reference
    private IAswerRedisService redisService;

    @Scheduled(cron="0 0 0/1 * * ? ")
    public void doWork(){
        //获取所有以stategy_statis_vo为前缀的vo对象, 使用模糊查询stategy_statis_vo:*
        //遍历所有vo的list集合, 更新vo对应strategyDetail中值
        List<StrategyStatisVO> vos = strategyStatisRedisService.getStatisVos(); //获取所有vo
        for (StrategyStatisVO vo : vos) {
            strategyDetailService.updateStatisData(vo); //更新mysql中攻略明细统计数据
        }
        System.out.println("同步redis数据到mysql中了");
    }
    @Scheduled(cron="0 0 0/1 * * ? ")
    public void doWork1(){
        //获取所有以stategy_statis_vo为前缀的vo对象, 使用模糊查询stategy_statis_vo:*
        //遍历所有vo的list集合, 更新vo对应strategyDetail中值
        List<AswerStatisVo> aswVoAll = redisService.getAswVoAll();//获取所有vo
        for (AswerStatisVo vo : aswVoAll) {

            answerCommentService.updateStatisData(vo); //更新MongoDB中攻略明细统计数据
        }
        System.out.println("同步redis数据到mysql中了");
    }
}
